<template>
  <div class="homepage-hero-module">
    <div class="video-container">
      <div :style="fixStyle"
           class="filter"></div>
      <video muted
             :style="fixStyle"
             autoplay
             loop
             class="fillWidth"
             v-on:canplay="canplay">
        <source src="../assets/loginbg.mp4"
                type="video/mp4" />浏览器不支持 video 标签，建议升级浏览器。
        <source src="../assets/loginbg.mp4"
                type="video/webm" />浏览器不支持 video 标签，建议升级浏览器。
      </video>
      <div class="poster hidden"
           v-if="!vedioCanPlay">
        <!-- <img :style="fixStyle" src="../assets/loginbg.jpg" alt /> -->
      </div>
    </div>

    <div class="ms-login">
      <div class="ms-title">后台管理系统</div>
      <el-form :model="loginForm"
               ref="loginFormRef"
               :rules="loginFornRules"
               label-width="0px"
               class="ms-content">
        <el-form-item prop="mgName">
          <el-input v-model="loginForm.mgName"
                    placeholder="mgName">
            <el-button slot="prepend"
                       icon="el-icon-user-solid"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item prop="mgPwd">
          <el-input v-model="loginForm.mgPwd"
                    placeholder="mgPwd"
                    type="password">
            <el-button slot="prepend"
                       icon="el-icon-lock"></el-button>
          </el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary"
                     @click="login">登录</el-button>
        </div>
        <p class="login-tips">提示 : 注册及重置密码请联系管理员。</p>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      vedioCanPlay: false,
      fixStyle: '',
      loginForm: {
        mgName: 'admin',
        mgPwd: '123456'
      },
      // 输入校验
      loginFornRules: {
        mgName: [
          { required: true, message: '请输入登录名', trigger: 'blur' },
          { min: 3, max: 11, message: '长度应在3到11个字符', trigger: 'blur' }
        ],
        mgPwd: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 3, max: 15, message: '长度应在3到15个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    canplay () {
      this.vedioCanPlay = true
    },
    login () {
      this.$refs.loginFormRef.validate(async valid => {
        if (valid) {
          const { data: res } = await this.$http.post('/api/mg_login', this.loginForm)
          if (res.meta.status !== 200) {
            return this.$message.error('登陆失败:' + res.meta.msg)
          } else {
            window.sessionStorage.setItem('token', res.data.token)
            this.$router.push('/home')
            return this.$message.success('登录成功！')
          }
        }
      })
    }
  }
}
</script>

<style scoped>
.homepage-hero-module,
.video-container {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.video-container .poster img,
.video-container video {
  z-index: 0;
  position: absolute;
}

.video-container .filter {
  z-index: 1;
  position: absolute;
  background: rgba(0, 0, 0, 0.4);
}
.login-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}
.ms-title {
  width: 100%;
  line-height: 50px;
  text-align: center;
  font-size: 20px;
  color: white;
  border-bottom: 1px solid #ddd;
}
.ms-login {
  z-index: 2;
  position: absolute;
  left: 50%;
  top: 50%;
  width: 380px;
  margin: -190px 0 0 -175px;
  border-radius: 5px;
  background: rgba(100, 100, 100, 0.2);
  overflow: hidden;
}
.ms-content {
  padding: 30px 30px;
}
.login-btn {
  text-align: center;
}
.login-btn button {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
}
.login-tips {
  font-size: 12px;
  line-height: 30px;
  color: #fff;
}
</style>
